package cn.mastor.order.controller;

import cn.mastor.order.service.IOrderProductDetailService;
import cn.mastor.order.domain.OrderProductDetail;
import cn.mastor.order.query.OrderProductDetailQuery;
import cn.mastor.basic.util.AjaxResult;
import cn.mastor.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/orderProductDetail")
public class OrderProductDetailController {
    @Autowired
    public IOrderProductDetailService orderProductDetailService;


    /**
     * 保存和修改公用的
     * @param orderProductDetail  传递的实体
     * @return AjaxResult转换结果
     */
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody OrderProductDetail orderProductDetail){
        try {
            if( orderProductDetail.getId()!=null)
                orderProductDetailService.update(orderProductDetail);
            else
                orderProductDetailService.add(orderProductDetail);
            return AjaxResult.me().success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().fail();
        }
    }
    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @DeleteMapping(value="/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            orderProductDetailService.delete(id);

        } catch (Exception e) {
        e.printStackTrace();
        }
        return AjaxResult.me().success();
    }
	
    //获取用户
    @GetMapping("/{id}")
    public OrderProductDetail get(@PathVariable("id")Long id)
    {
        return orderProductDetailService.findById(id);
    }


    /**
    * 查看所有的员工信息
    * @return
    */
    @GetMapping()
    public List<OrderProductDetail> list(){

        return orderProductDetailService.findAll();
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping("/list")
    public PageList<OrderProductDetail> json(@RequestBody OrderProductDetailQuery query)
    {
        return orderProductDetailService.queryByPage(query);
    }
}
